package com.ruoyi.task;

import com.ruoyi.common.core.domain.entity.SysArea;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.develop.goodsFee.domain.GoodsFee;
import com.ruoyi.develop.goodsFee.service.IGoodsFeeService;
import com.ruoyi.develop.goodsOrderIn.domain.GoodsOrderIn;
import com.ruoyi.develop.goodsOrderIn.service.IGoodsOrderInService;
import com.ruoyi.develop.goodsReceipt.service.IGoodsReceiptService;
import com.ruoyi.develop.goodsReimbursement.domain.GoodsReimbursement;
import com.ruoyi.develop.goodsReimbursement.service.IGoodsReimbursementService;
import com.ruoyi.develop.goodsSale.domain.GoodsSale;
import com.ruoyi.develop.goodsSale.service.IGoodsSaleService;
import com.ruoyi.develop.goodsStatistics.domain.GoodsStatistics;
import com.ruoyi.develop.goodsStatistics.service.IGoodsStatisticsService;
import com.ruoyi.develop.projectBaseInfo.domain.ProjectBaseInfo;
import com.ruoyi.develop.projectBaseInfo.service.IProjectBaseInfoService;
import com.ruoyi.system.service.ISysAreaService;
import com.ruoyi.system.service.ISysDeptService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.*;

/**
 * 定时任务
 *
 * @author lmm
 */
@Component("updateStatisticsTask")
public class UpdateStatisticsTask {

    public static RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
    public static ISysDeptService deptService = SpringUtils.getBean(ISysDeptService.class);
    public static IGoodsOrderInService orderInService = SpringUtils.getBean(IGoodsOrderInService.class);
    public static IGoodsStatisticsService statisticsService = SpringUtils.getBean(IGoodsStatisticsService.class);
    public static IGoodsSaleService saleService = SpringUtils.getBean(IGoodsSaleService.class);
    public static IGoodsFeeService feeService = SpringUtils.getBean(IGoodsFeeService.class);
    public static IProjectBaseInfoService projectBaseInfoService = SpringUtils.getBean(IProjectBaseInfoService.class);
    public static IGoodsReimbursementService imburseMentService = SpringUtils.getBean(IGoodsReimbursementService.class);

    public static String LOCK_KEY = "UpdateStatisticsTask:lock";

    public void run() {
        if (redisCache.hasKey(LOCK_KEY)) {
            return;
        }
        //TODO将数据导入历史表
        String year = DateUtils.formatDate(new Date(), "yyyy");
        statisticsService.restoreData(year);
        //TODO清空统计数据表
        statisticsService.truncateData();
        try {
            Date insertTime = new Date();

            List<SysDept> deptList = deptService.selectAllDept(new SysDept());
            for (SysDept dept : deptList) {

                GoodsStatistics statistics = new GoodsStatistics();

                statistics.setDeptId(dept.getDeptId());
                statistics.setDeptName(dept.getDeptName());
                statistics.setSort(dept.getOrderNum());
                statistics.setInsertTime(insertTime);

                //goods_order_in 表 : 入库数据统计 | 库存数据统计(库存告警) |
                //TODO 采购报销 : 自采 | 公采 (根据采购时间进行)
                goodsOrderInTable(insertTime, dept, statistics);

                //TODOgoods_sale 表 : 销售数据统计 | 零散销售利润统计 |
                //TODO应收数据 :
                goodsSaleTable(insertTime, dept, statistics);

                //TODOgoods_fee 表 : 开发经费统计 | 经费报销(根据经费发生时间)
                goodsFeeTable(insertTime, dept, statistics);

                //TODOproject_base_info 表 : 项目相关统计
                projectTable(insertTime, dept, statistics);

                //TODO应收相关统计(销售统计和项目统计分别体现)

                //TODD报销相关统计(入库统计和经费统计分别体现)
                //TODO 报销数据统计
                reImbursementTable(insertTime, dept, statistics);



            }
            redisCache.deleteObject(LOCK_KEY);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void reImbursementTable(Date insertTime, SysDept dept, GoodsStatistics statistics){
        //报销统计 自采报销     公采报销        经费报销    本周/本月/本季度/本年        报销条目数/报销金额      已通过条目数/金额       已发放条目数/金额
//        GoodsStatistics statistics16 = new GoodsStatistics();
        GoodsStatistics statistics17 = new GoodsStatistics();
        GoodsStatistics statistics18 = new GoodsStatistics();
        GoodsStatistics statistics19 = new GoodsStatistics();
        GoodsStatistics statistics20 = new GoodsStatistics();

        GoodsStatistics statistics21 = new GoodsStatistics();
        GoodsStatistics statistics22 = new GoodsStatistics();
        GoodsStatistics statistics23 = new GoodsStatistics();
        GoodsStatistics statistics24 = new GoodsStatistics();

        GoodsStatistics statistics25 = new GoodsStatistics();
        GoodsStatistics statistics26 = new GoodsStatistics();
        GoodsStatistics statistics27 = new GoodsStatistics();
        GoodsStatistics statistics28 = new GoodsStatistics();

        GoodsReimbursement imburseParam = new GoodsReimbursement();
        Map<String, Object> saleMap = new HashMap<>();
        saleMap.put("year", DateUtils.formatDate(insertTime, "yyyy"));
        saleMap.put("statisticsDeptId", dept.getDeptId());
        imburseParam.setParams(saleMap);
        List<GoodsReimbursement> goodsReimbursements = imburseMentService.selectListNoScope(imburseParam);
//        BeanUtils.copyProperties(statistics, statistics16);
        BeanUtils.copyProperties(statistics, statistics17);
        BeanUtils.copyProperties(statistics, statistics18);
        BeanUtils.copyProperties(statistics, statistics19);
        BeanUtils.copyProperties(statistics, statistics20);

        BeanUtils.copyProperties(statistics, statistics21);
        BeanUtils.copyProperties(statistics, statistics22);
        BeanUtils.copyProperties(statistics, statistics23);
        BeanUtils.copyProperties(statistics, statistics24);

        BeanUtils.copyProperties(statistics, statistics25);
        BeanUtils.copyProperties(statistics, statistics26);
        BeanUtils.copyProperties(statistics, statistics27);
        BeanUtils.copyProperties(statistics, statistics28);
//        statistics16.setCategory("bxtj");
        statistics21.setCategory("gcbxtj");
        statistics22.setCategory("gcbxtj");
        statistics23.setCategory("gcbxtj");
        statistics24.setCategory("gcbxtj");
        statistics17.setCategory("zcbxtj");
        statistics18.setCategory("zcbxtj");
        statistics19.setCategory("zcbxtj");
        statistics20.setCategory("zcbxtj");
        statistics25.setCategory("jfbxtj");
        statistics26.setCategory("jfbxtj");
        statistics27.setCategory("jfbxtj");
        statistics28.setCategory("jfbxtj");

//        statistics16.setKind("");
        statistics17.setKind("week");
        statistics18.setKind("month");
        statistics19.setKind("season");
        statistics20.setKind("year");
        statistics21.setKind("week");
        statistics22.setKind("month");
        statistics23.setKind("season");
        statistics24.setKind("year");
        statistics25.setKind("week");
        statistics26.setKind("month");
        statistics27.setKind("season");
        statistics28.setKind("year");

        //公采本周
        int gcbzbxCount = 0;
        BigDecimal gcbzbxMoney = BigDecimal.ZERO;
        int gcbztgCount = 0;
        BigDecimal gcbztgMoney = BigDecimal.ZERO;
        int gcbzffCount = 0;
        BigDecimal gcbzffMoney = BigDecimal.ZERO;
        //公采本月
        int gcbybxCount = 0;
        BigDecimal gcbybxMoney = BigDecimal.ZERO;
        int gcbytgCount = 0;
        BigDecimal gcbytgMoney = BigDecimal.ZERO;
        int gcbyffCount = 0;
        BigDecimal gcbyffMoney = BigDecimal.ZERO;
        //公采本季度
        int gcbjdbxCount = 0;
        BigDecimal gcbjdbxMoney = BigDecimal.ZERO;
        int gcbjdtgCount = 0;
        BigDecimal gcbjdtgMoney = BigDecimal.ZERO;
        int gcbjdffCount = 0;
        BigDecimal gcbjdffMoney = BigDecimal.ZERO;
        //公采本年
        int gcbnbxCount = 0;
        BigDecimal gcbnbxMoney = BigDecimal.ZERO;
        int gcbntgCount = 0;
        BigDecimal gcbntgMoney = BigDecimal.ZERO;
        int gcbnffCount = 0;
        BigDecimal gcbnffMoney = BigDecimal.ZERO;
        //自采本周
        int zcbzbxCount = 0;
        BigDecimal zcbzbxMoney = BigDecimal.ZERO;
        int zcbztgCount = 0;
        BigDecimal zcbztgMoney = BigDecimal.ZERO;
        int zcbzffCount = 0;
        BigDecimal zcbzffMoney = BigDecimal.ZERO;
        //自采本月
        int zcbybxCount = 0;
        BigDecimal zcbybxMoney = BigDecimal.ZERO;
        int zcbytgCount = 0;
        BigDecimal zcbytgMoney = BigDecimal.ZERO;
        int zcbyffCount = 0;
        BigDecimal zcbyffMoney = BigDecimal.ZERO;
        //自采本季度
        int zcbjdbxCount = 0;
        BigDecimal zcbjdbxMoney = BigDecimal.ZERO;
        int zcbjdtgCount = 0;
        BigDecimal zcbjdtgMoney = BigDecimal.ZERO;
        int zcbjdffCount = 0;
        BigDecimal zcbjdffMoney = BigDecimal.ZERO;
        //自采本年
        int zcbnbxCount = 0;
        BigDecimal zcbnbxMoney = BigDecimal.ZERO;
        int zcbntgCount = 0;
        BigDecimal zcbntgMoney = BigDecimal.ZERO;
        int zcbnffCount = 0;
        BigDecimal zcbnffMoney = BigDecimal.ZERO;
        //经费本周
        int jfbzbxCount = 0;
        BigDecimal jfbzbxMoney = BigDecimal.ZERO;
        int jfbztgCount = 0;
        BigDecimal jfbztgMoney = BigDecimal.ZERO;
        int jfbzffCount = 0;
        BigDecimal jfbzffMoney = BigDecimal.ZERO;
        //经费本月
        int jfbybxCount = 0;
        BigDecimal jfbybxMoney = BigDecimal.ZERO;
        int jfbytgCount = 0;
        BigDecimal jfbytgMoney = BigDecimal.ZERO;
        int jfbyffCount = 0;
        BigDecimal jfbyffMoney = BigDecimal.ZERO;
        //经费本季度
        int jfbjdbxCount = 0;
        BigDecimal jfbjdbxMoney = BigDecimal.ZERO;
        int jfbjdtgCount = 0;
        BigDecimal jfbjdtgMoney = BigDecimal.ZERO;
        int jfbjdffCount = 0;
        BigDecimal jfbjdffMoney = BigDecimal.ZERO;
        //经费本年
        int jfbnbxCount = 0;
        BigDecimal jfbnbxMoney = BigDecimal.ZERO;
        int jfbntgCount = 0;
        BigDecimal jfbntgMoney = BigDecimal.ZERO;
        int jfbnffCount = 0;
        BigDecimal jfbnffMoney = BigDecimal.ZERO;

        for (GoodsReimbursement imburse : goodsReimbursements){
            if("0".equals(imburse.getType())){//公采
                if (DateUtils.isWithinCurrentRange(imburse.getImburseDate(), "week")) {
                    gcbzbxCount ++;
                    gcbzbxMoney = gcbzbxMoney.add(imburse.getImburseMoney());
                    if("1".equals(imburse.getStatus())){//审核通过
                        gcbztgCount ++;
                        gcbztgMoney = gcbztgMoney.add(imburse.getImburseMoney());
                    }else if("2".equals(imburse.getStatus())){//发放完毕
                        gcbzffCount ++;
                        gcbzffMoney = gcbzffMoney.add(imburse.getImburseMoney());
                    }
                }
                if (DateUtils.isWithinCurrentRange(imburse.getImburseDate(), "month")) {
                    gcbybxCount ++;
                    gcbybxMoney = gcbybxMoney.add(imburse.getImburseMoney());
                    if("1".equals(imburse.getStatus())){//审核通过
                        gcbytgCount ++;
                        gcbytgMoney = gcbytgMoney.add(imburse.getImburseMoney());
                    }else if("2".equals(imburse.getStatus())){//发放完毕
                        gcbyffCount ++;
                        gcbyffMoney = gcbyffMoney.add(imburse.getImburseMoney());
                    }
                }
                if (DateUtils.isWithinCurrentRange(imburse.getImburseDate(), "season")) {
                    gcbjdbxCount ++;
                    gcbjdbxMoney = gcbjdbxMoney.add(imburse.getImburseMoney());
                    if("1".equals(imburse.getStatus())){//审核通过
                        gcbjdtgCount ++;
                        gcbjdtgMoney = gcbjdtgMoney.add(imburse.getImburseMoney());
                    }else if("2".equals(imburse.getStatus())){//发放完毕
                        gcbjdffCount ++;
                        gcbjdffMoney = gcbjdffMoney.add(imburse.getImburseMoney());
                    }
                }
                gcbnbxCount ++;
                gcbnbxMoney = gcbnbxMoney.add(imburse.getImburseMoney());
                if("1".equals(imburse.getStatus())){//审核通过
                    gcbntgCount ++;
                    gcbntgMoney = gcbntgMoney.add(imburse.getImburseMoney());
                }else if("2".equals(imburse.getStatus())){//发放完毕
                    gcbnffCount ++;
                    gcbnffMoney = gcbnffMoney.add(imburse.getImburseMoney());
                }
            }else if("1".equals(imburse.getType())){//自采
                if (DateUtils.isWithinCurrentRange(imburse.getImburseDate(), "week")) {
                    zcbzbxCount ++;
                    zcbzbxMoney = zcbzbxMoney.add(imburse.getImburseMoney());
                    if("1".equals(imburse.getStatus())){//审核通过
                        zcbztgCount ++;
                        zcbztgMoney = zcbztgMoney.add(imburse.getImburseMoney());
                    }else if("2".equals(imburse.getStatus())){//发放完毕
                        zcbzffCount ++;
                        zcbzffMoney = zcbzffMoney.add(imburse.getImburseMoney());
                    }
                }
                if (DateUtils.isWithinCurrentRange(imburse.getImburseDate(), "month")) {
                    zcbybxCount ++;
                    zcbybxMoney = zcbybxMoney.add(imburse.getImburseMoney());
                    if("1".equals(imburse.getStatus())){//审核通过
                        zcbytgCount ++;
                        zcbytgMoney = zcbytgMoney.add(imburse.getImburseMoney());
                    }else if("2".equals(imburse.getStatus())){//发放完毕
                        zcbyffCount ++;
                        zcbyffMoney = zcbyffMoney.add(imburse.getImburseMoney());
                    }
                }
                if (DateUtils.isWithinCurrentRange(imburse.getImburseDate(), "season")) {
                    zcbjdbxCount ++;
                    zcbjdbxMoney = zcbjdbxMoney.add(imburse.getImburseMoney());
                    if("1".equals(imburse.getStatus())){//审核通过
                        zcbjdtgCount ++;
                        zcbjdtgMoney = zcbjdtgMoney.add(imburse.getImburseMoney());
                    }else if("2".equals(imburse.getStatus())){//发放完毕
                        zcbjdffCount ++;
                        zcbjdffMoney = zcbjdffMoney.add(imburse.getImburseMoney());
                    }
                }
                zcbnbxCount ++;
                zcbnbxMoney = zcbnbxMoney.add(imburse.getImburseMoney());
                if("1".equals(imburse.getStatus())){//审核通过
                    zcbntgCount ++;
                    zcbntgMoney = zcbntgMoney.add(imburse.getImburseMoney());
                }else if("2".equals(imburse.getStatus())){//发放完毕
                    zcbnffCount ++;
                    zcbnffMoney = zcbnffMoney.add(imburse.getImburseMoney());
                }
            }else if("2".equals(imburse.getType())){//经费
                if (DateUtils.isWithinCurrentRange(imburse.getImburseDate(), "week")) {
                    jfbzbxCount ++;
                    jfbzbxMoney = jfbzbxMoney.add(imburse.getImburseMoney());
                    if("1".equals(imburse.getStatus())){//审核通过
                        jfbztgCount ++;
                        jfbztgMoney = jfbztgMoney.add(imburse.getImburseMoney());
                    }else if("2".equals(imburse.getStatus())){//发放完毕
                        jfbzffCount ++;
                        jfbzffMoney = jfbzffMoney.add(imburse.getImburseMoney());
                    }
                }
                if (DateUtils.isWithinCurrentRange(imburse.getImburseDate(), "month")) {
                    jfbybxCount ++;
                    jfbybxMoney = jfbybxMoney.add(imburse.getImburseMoney());
                    if("1".equals(imburse.getStatus())){//审核通过
                        jfbytgCount ++;
                        jfbytgMoney = jfbytgMoney.add(imburse.getImburseMoney());
                    }else if("2".equals(imburse.getStatus())){//发放完毕
                        jfbyffCount ++;
                        jfbyffMoney = jfbyffMoney.add(imburse.getImburseMoney());
                    }
                }
                if (DateUtils.isWithinCurrentRange(imburse.getImburseDate(), "season")) {
                    jfbjdbxCount ++;
                    jfbjdbxMoney = jfbjdbxMoney.add(imburse.getImburseMoney());
                    if("1".equals(imburse.getStatus())){//审核通过
                        jfbjdtgCount ++;
                        jfbjdtgMoney = jfbjdtgMoney.add(imburse.getImburseMoney());
                    }else if("2".equals(imburse.getStatus())){//发放完毕
                        jfbjdffCount ++;
                        jfbjdffMoney = jfbjdffMoney.add(imburse.getImburseMoney());
                    }
                }
                jfbnbxCount ++;
                jfbnbxMoney = jfbnbxMoney.add(imburse.getImburseMoney());
                if("1".equals(imburse.getStatus())){//审核通过
                    jfbntgCount ++;
                    jfbntgMoney = jfbntgMoney.add(imburse.getImburseMoney());
                }else if("2".equals(imburse.getStatus())){//发放完毕
                    jfbnffCount ++;
                    jfbnffMoney = jfbnffMoney.add(imburse.getImburseMoney());
                }
            }
        }
        statistics17.setCount1(new BigDecimal(gcbzbxCount));
        statistics17.setMoney1(gcbzbxMoney);
        statistics17.setCount2(new BigDecimal(gcbztgCount));
        statistics17.setMoney2(gcbztgMoney);
        statistics17.setCount3(new BigDecimal(gcbzffCount));
        statistics17.setMoney3(gcbzffMoney);
        statisticsService.insertNoScope(statistics17);

        statistics18.setCount1(new BigDecimal(gcbybxCount));
        statistics18.setMoney1(gcbybxMoney);
        statistics18.setCount2(new BigDecimal(gcbytgCount));
        statistics18.setMoney2(gcbytgMoney);
        statistics18.setCount3(new BigDecimal(gcbyffCount));
        statistics18.setMoney3(gcbyffMoney);
        statisticsService.insertNoScope(statistics18);

        statistics19.setCount1(new BigDecimal(gcbjdbxCount));
        statistics19.setMoney1(gcbjdbxMoney);
        statistics19.setCount2(new BigDecimal(gcbjdtgCount));
        statistics19.setMoney2(gcbjdtgMoney);
        statistics19.setCount3(new BigDecimal(gcbjdffCount));
        statistics19.setMoney3(gcbjdffMoney);
        statisticsService.insertNoScope(statistics19);

        statistics20.setCount1(new BigDecimal(gcbnbxCount));
        statistics20.setMoney1(gcbnbxMoney);
        statistics20.setCount2(new BigDecimal(gcbntgCount));
        statistics20.setMoney2(gcbntgMoney);
        statistics20.setCount3(new BigDecimal(gcbnffCount));
        statistics20.setMoney3(gcbnffMoney);
        statisticsService.insertNoScope(statistics20);

        statistics21.setCount1(new BigDecimal(zcbzbxCount));
        statistics21.setMoney1(zcbzbxMoney);
        statistics21.setCount2(new BigDecimal(zcbztgCount));
        statistics21.setMoney2(zcbztgMoney);
        statistics21.setCount3(new BigDecimal(zcbzffCount));
        statistics21.setMoney3(zcbzffMoney);
        statisticsService.insertNoScope(statistics21);

        statistics22.setCount1(new BigDecimal(zcbybxCount));
        statistics22.setMoney1(zcbybxMoney);
        statistics22.setCount2(new BigDecimal(zcbytgCount));
        statistics22.setMoney2(zcbytgMoney);
        statistics22.setCount3(new BigDecimal(zcbyffCount));
        statistics22.setMoney3(zcbyffMoney);
        statisticsService.insertNoScope(statistics22);

        statistics23.setCount1(new BigDecimal(zcbjdbxCount));
        statistics23.setMoney1(zcbjdbxMoney);
        statistics23.setCount2(new BigDecimal(zcbjdtgCount));
        statistics23.setMoney2(zcbjdtgMoney);
        statistics23.setCount3(new BigDecimal(zcbjdffCount));
        statistics23.setMoney3(zcbjdffMoney);
        statisticsService.insertNoScope(statistics23);

        statistics24.setCount1(new BigDecimal(zcbnbxCount));
        statistics24.setMoney1(zcbnbxMoney);
        statistics24.setCount2(new BigDecimal(zcbntgCount));
        statistics24.setMoney2(zcbntgMoney);
        statistics24.setCount3(new BigDecimal(zcbnffCount));
        statistics24.setMoney3(zcbnffMoney);
        statisticsService.insertNoScope(statistics24);

        statistics25.setCount1(new BigDecimal(jfbzbxCount));
        statistics25.setMoney1(jfbzbxMoney);
        statistics25.setCount2(new BigDecimal(jfbztgCount));
        statistics25.setMoney2(jfbztgMoney);
        statistics25.setCount3(new BigDecimal(jfbzffCount));
        statistics25.setMoney3(jfbzffMoney);
        statisticsService.insertNoScope(statistics25);

        statistics26.setCount1(new BigDecimal(jfbybxCount));
        statistics26.setMoney1(jfbybxMoney);
        statistics26.setCount2(new BigDecimal(jfbytgCount));
        statistics26.setMoney2(jfbytgMoney);
        statistics26.setCount3(new BigDecimal(jfbyffCount));
        statistics26.setMoney3(jfbyffMoney);
        statisticsService.insertNoScope(statistics26);

        statistics27.setCount1(new BigDecimal(jfbjdbxCount));
        statistics27.setMoney1(jfbjdbxMoney);
        statistics27.setCount2(new BigDecimal(jfbjdtgCount));
        statistics27.setMoney2(jfbjdtgMoney);
        statistics27.setCount3(new BigDecimal(jfbjdffCount));
        statistics27.setMoney3(jfbjdffMoney);
        statisticsService.insertNoScope(statistics27);

        statistics28.setCount1(new BigDecimal(jfbnbxCount));
        statistics28.setMoney1(jfbnbxMoney);
        statistics28.setCount2(new BigDecimal(jfbntgCount));
        statistics28.setMoney2(jfbntgMoney);
        statistics28.setCount3(new BigDecimal(jfbnffCount));
        statistics28.setMoney3(jfbnffMoney);
        statisticsService.insertNoScope(statistics28);
    }

    private void projectTable(Date insertTime, SysDept dept, GoodsStatistics statistics){
        //项目统计  //项目数量        //项目金额        //已开票        //未开票        //已回款        //未回款        //销售成本        //销售金额        //开发经费        //利润      //应收
        GoodsStatistics statistics6 = new GoodsStatistics();
        GoodsStatistics statistics7 = new GoodsStatistics();
        GoodsStatistics statistics8 = new GoodsStatistics();
        ProjectBaseInfo prjParam = new ProjectBaseInfo();
        Map<String, Object> saleMap = new HashMap<>();
        saleMap.put("year", DateUtils.formatDate(insertTime, "yyyy"));
        saleMap.put("statisticsDeptId", dept.getDeptId());
        prjParam.setParams(saleMap);
        List<ProjectBaseInfo> projects = projectBaseInfoService.selectListNoScope(prjParam);
        BeanUtils.copyProperties(statistics, statistics6);
        BeanUtils.copyProperties(statistics, statistics7);
        BeanUtils.copyProperties(statistics, statistics8);
        statistics6.setCategory("xmtj");
        statistics6.setKind("month");
        statistics7.setCategory("xmtj");
        statistics7.setKind("season");
        statistics8.setCategory("xmtj");
        statistics8.setKind("year");
        int xmCountM = 0;
        BigDecimal xmMoneyM = BigDecimal.ZERO;
        int xmykpCountM = 0;
        BigDecimal ykpMoneyM = BigDecimal.ZERO;
        int xmwkpCountM = 0;
        BigDecimal wkpMoneyM = BigDecimal.ZERO;
        int xmyhkCountM = 0;
        BigDecimal yhkMoneyM = BigDecimal.ZERO;
        int xmwhkCountM = 0;
        BigDecimal whkMoneyM = BigDecimal.ZERO;
        BigDecimal xscbMoneyM = BigDecimal.ZERO;
        BigDecimal xsjeMoneyM = BigDecimal.ZERO;
        BigDecimal kfjfMoneyM = BigDecimal.ZERO;
        BigDecimal lrMoneyM = BigDecimal.ZERO;
        BigDecimal ysMoneyM = BigDecimal.ZERO;

        int xmCountS = 0;
        BigDecimal xmMoneyS = BigDecimal.ZERO;
        int xmykpCountS = 0;
        BigDecimal ykpMoneyS = BigDecimal.ZERO;
        int xmwkpCountS = 0;
        BigDecimal wkpMoneyS = BigDecimal.ZERO;
        int xmyhkCountS = 0;
        BigDecimal yhkMoneyS = BigDecimal.ZERO;
        int xmwhkCountS = 0;
        BigDecimal whkMoneyS = BigDecimal.ZERO;
        BigDecimal xscbMoneyS = BigDecimal.ZERO;
        BigDecimal xsjeMoneyS = BigDecimal.ZERO;
        BigDecimal kfjfMoneyS = BigDecimal.ZERO;
        BigDecimal lrMoneyS = BigDecimal.ZERO;
        BigDecimal ysMoneyS = BigDecimal.ZERO;

        int xmCountY = 0;
        BigDecimal xmMoneyY = BigDecimal.ZERO;
        int xmykpCountY = 0;
        BigDecimal ykpMoneyY = BigDecimal.ZERO;
        int xmwkpCountY = 0;
        BigDecimal wkpMoneyY = BigDecimal.ZERO;
        int xmyhkCountY = 0;
        BigDecimal yhkMoneyY = BigDecimal.ZERO;
        int xmwhkCountY = 0;
        BigDecimal whkMoneyY = BigDecimal.ZERO;
        BigDecimal xscbMoneyY = BigDecimal.ZERO;
        BigDecimal xsjeMoneyY = BigDecimal.ZERO;
        BigDecimal kfjfMoneyY = BigDecimal.ZERO;
        BigDecimal lrMoneyY = BigDecimal.ZERO;
        BigDecimal ysMoneyY = BigDecimal.ZERO;

        for(ProjectBaseInfo project : projects){
            if (DateUtils.isWithinCurrentRange(project.getCreateTime(), "month")) {
                xmCountM ++;
                ykpMoneyM = ykpMoneyM.add(project.getTaxAll());
                wkpMoneyM = wkpMoneyM.add(project.getTaxRemain());
                yhkMoneyM = yhkMoneyM.add(project.getBackMoney());
                whkMoneyM = whkMoneyM.add(project.getRemainMoney());
                xscbMoneyM = xscbMoneyM.add(project.getBuyMoney());
                xsjeMoneyM = xsjeMoneyM.add(project.getSaleMoney());
                kfjfMoneyM = kfjfMoneyM.add(project.getFeeMoney());
                lrMoneyM = lrMoneyM.add(project.getProfitMoney());
                ysMoneyM = xmMoneyM.subtract(yhkMoneyM);
            }
            if (DateUtils.isWithinCurrentRange(project.getCreateTime(), "season")) {
                xmCountS ++;
                ykpMoneyS = ykpMoneyS.add(project.getTaxAll());
                wkpMoneyS = wkpMoneyS.add(project.getTaxRemain());
                yhkMoneyS = yhkMoneyS.add(project.getBackMoney());
                whkMoneyS = whkMoneyS.add(project.getRemainMoney());
                xscbMoneyS = xscbMoneyS.add(project.getBuyMoney());
                xsjeMoneyS = xsjeMoneyS.add(project.getSaleMoney());
                kfjfMoneyS = kfjfMoneyS.add(project.getFeeMoney());
                lrMoneyS = lrMoneyS.add(project.getProfitMoney());
                ysMoneyS = xmMoneyS.subtract(yhkMoneyS);
            }
            xmCountY ++;
            ykpMoneyY = ykpMoneyY.add(project.getTaxAll());
            wkpMoneyY = wkpMoneyY.add(project.getTaxRemain());
            yhkMoneyY = yhkMoneyY.add(project.getBackMoney());
            whkMoneyY = whkMoneyY.add(project.getRemainMoney());
            xscbMoneyY = xscbMoneyY.add(project.getBuyMoney());
            xsjeMoneyY = xsjeMoneyY.add(project.getSaleMoney());
            kfjfMoneyY = kfjfMoneyY.add(project.getFeeMoney());
            lrMoneyY = lrMoneyY.add(project.getProfitMoney());
            ysMoneyY = xmMoneyY.subtract(yhkMoneyY);
        }
        statistics6.setCount1(new BigDecimal(xmCountM));
        statistics6.setMoney1(xmMoneyM);
        statistics6.setCount2(new BigDecimal(xmykpCountM));
        statistics6.setMoney2(ykpMoneyM);
        statistics6.setCount3(new BigDecimal(xmwkpCountM));
        statistics6.setMoney3(wkpMoneyM);
        statistics6.setCount4(new BigDecimal(xmyhkCountM));
        statistics6.setMoney4(yhkMoneyM);
        statistics6.setCount5(new BigDecimal(xmwhkCountM));
        statistics6.setMoney5(whkMoneyM);
        statistics6.setMoney6(xscbMoneyM);
        statistics6.setMoney7(xsjeMoneyM);
        statistics6.setMoney8(kfjfMoneyM);
        statistics6.setMoney9(lrMoneyM);
        statistics6.setMoney(ysMoneyM);
        statisticsService.insertNoScope(statistics6);

        statistics7.setCount1(new BigDecimal(xmCountS));
        statistics7.setMoney1(xmMoneyS);
        statistics7.setCount2(new BigDecimal(xmykpCountS));
        statistics7.setMoney2(ykpMoneyS);
        statistics7.setCount3(new BigDecimal(xmwkpCountS));
        statistics7.setMoney3(wkpMoneyS);
        statistics7.setCount4(new BigDecimal(xmyhkCountS));
        statistics7.setMoney4(yhkMoneyS);
        statistics7.setCount5(new BigDecimal(xmwhkCountS));
        statistics7.setMoney5(whkMoneyS);
        statistics7.setMoney6(xscbMoneyS);
        statistics7.setMoney7(xsjeMoneyS);
        statistics7.setMoney8(kfjfMoneyS);
        statistics7.setMoney9(lrMoneyS);
        statistics7.setMoney(ysMoneyS);
        statisticsService.insertNoScope(statistics7);

        statistics8.setCount1(new BigDecimal(xmCountY));
        statistics8.setMoney1(xmMoneyY);
        statistics8.setCount2(new BigDecimal(xmykpCountY));
        statistics8.setMoney2(ykpMoneyY);
        statistics8.setCount3(new BigDecimal(xmwkpCountY));
        statistics8.setMoney3(wkpMoneyY);
        statistics8.setCount4(new BigDecimal(xmyhkCountY));
        statistics8.setMoney4(yhkMoneyY);
        statistics8.setCount5(new BigDecimal(xmwhkCountY));
        statistics8.setMoney5(whkMoneyY);
        statistics8.setMoney6(xscbMoneyY);
        statistics8.setMoney7(xsjeMoneyY);
        statistics8.setMoney8(kfjfMoneyY);
        statistics8.setMoney9(lrMoneyY);
        statistics8.setMoney(ysMoneyY);
        statisticsService.insertNoScope(statistics8);
    }

    private void goodsFeeTable(Date insertTime, SysDept dept, GoodsStatistics statistics) {
        //费用统计         // 本周费用                //本月费用                //本季度费用                //本年费用
        /*GoodsStatistics statistics5 = new GoodsStatistics();*/
        GoodsStatistics statistics12 = new GoodsStatistics();
        GoodsStatistics statistics13 = new GoodsStatistics();
        GoodsStatistics statistics14 = new GoodsStatistics();
        GoodsStatistics statistics15 = new GoodsStatistics();
        GoodsFee feeParam = new GoodsFee();
        Map<String, Object> saleMap = new HashMap<>();
        saleMap.put("year", DateUtils.formatDate(insertTime, "yyyy"));
        saleMap.put("statisticsDeptId", dept.getDeptId());
        feeParam.setParams(saleMap);
        List<GoodsFee> sales = feeService.selectListNoScope(feeParam);
        BeanUtils.copyProperties(statistics, statistics12);
        statistics12.setCategory("jftj");
        statistics12.setKind("week");
        BeanUtils.copyProperties(statistics, statistics13);
        statistics13.setCategory("jftj");
        statistics13.setKind("month");
        BeanUtils.copyProperties(statistics, statistics14);
        statistics14.setCategory("jftj");
        statistics14.setKind("season");
        BeanUtils.copyProperties(statistics, statistics15);
        statistics15.setCategory("jftj");
        statistics15.setKind("year");
        //本周经费 : 条目数  经费金额  已核销经费       未提交         未核销
        int bzjfCount= 0;
        BigDecimal bzjfMoney = BigDecimal.ZERO;
        BigDecimal bzyhxjfMoney = BigDecimal.ZERO;
        BigDecimal bzwtjjfMoney = BigDecimal.ZERO;
        BigDecimal bzwhxjfMoney = BigDecimal.ZERO;
        //本月经费 条目数  经费金额  已核销经费
        int byjfCount = 0;
        BigDecimal byjfMoney = BigDecimal.ZERO;
        BigDecimal byyhxjfMoney = BigDecimal.ZERO;
        BigDecimal bywtjjfMoney = BigDecimal.ZERO;
        BigDecimal bywhxjfMoney = BigDecimal.ZERO;
        //本季度经费 条目数  经费金额  已核销经费
        int bjdjfCount = 0;
        BigDecimal bjdjfMoney = BigDecimal.ZERO;
        BigDecimal bjdyhxjfMoney = BigDecimal.ZERO;
        BigDecimal bjdwtjjfMoney = BigDecimal.ZERO;
        BigDecimal bjdwhxjfMoney = BigDecimal.ZERO;
        //本年经费 条目数  经费金额  已核销经费
        int bnjfCount = 0;
        BigDecimal bnjfMoney = BigDecimal.ZERO;
        BigDecimal bnyhxjfMoney = BigDecimal.ZERO;
        BigDecimal bnwtjjfMoney = BigDecimal.ZERO;
        BigDecimal bnwhxjfMoney = BigDecimal.ZERO;

        for(GoodsFee fee : sales){
            if (DateUtils.isWithinCurrentRange(fee.getFeeDate(), "week")) {
                bzjfCount ++;
                bzjfMoney = bzjfMoney.add(fee.getMoney());
                if(StringUtils.isNotBlank(fee.getImburseId())){
                    if("yhx".equals(fee.getStatus())){
                        bzyhxjfMoney = bzyhxjfMoney.add(fee.getMoney());
                    }else{
                        bzwhxjfMoney = bzwhxjfMoney.add(fee.getMoney());
                    }
                }else{
                    bzwtjjfMoney = bzwtjjfMoney.add(fee.getMoney());
                }
            }
            if (DateUtils.isWithinCurrentRange(fee.getFeeDate(), "month")) {
                byjfCount ++;
                byjfMoney = byjfMoney.add(fee.getMoney());
                if(StringUtils.isNotBlank(fee.getImburseId())){
                    if("yhx".equals(fee.getStatus())){
                        byyhxjfMoney = byyhxjfMoney.add(fee.getMoney());
                    }else{
                        bywhxjfMoney = bywhxjfMoney.add(fee.getMoney());
                    }
                }else{
                    bywtjjfMoney = bywtjjfMoney.add(fee.getMoney());
                }
            }
            if (DateUtils.isWithinCurrentRange(fee.getFeeDate(), "season")) {
                bjdjfCount ++;
                bjdjfMoney = bjdjfMoney.add(fee.getMoney());
                if(StringUtils.isNotBlank(fee.getImburseId())){
                    if("yhx".equals(fee.getStatus())){
                        bjdyhxjfMoney = bjdyhxjfMoney.add(fee.getMoney());
                    }else{
                        bjdwhxjfMoney =  bjdwhxjfMoney.add(fee.getMoney());
                    }
                }else{
                    bjdwtjjfMoney = bjdwtjjfMoney.add(fee.getMoney());
                }
            }
            bnjfCount ++;
            bnjfMoney = bnjfMoney.add(fee.getMoney());
            if(StringUtils.isNotBlank(fee.getImburseId())){
                if("yhx".equals(fee.getStatus())){
                    bnyhxjfMoney = bnyhxjfMoney.add(fee.getMoney());
                }else{
                    bnwhxjfMoney =  bnwhxjfMoney.add(fee.getMoney());
                }
            }else{
                bnwtjjfMoney = bnwtjjfMoney.add(fee.getMoney());
            }
        }
        /*statistics5.setCount1(bzjfCount);
        statistics5.setMoney1(bzjfMoney);
        statistics5.setMoney2(bzyhxjfMoney);
        statistics5.setCount1(byjfCount);
        statistics5.setMoney1(byjfMoney);
        statistics5.setMoney2(byyhxjfMoney);
        statistics5.setMoney3(byyhxjfMoney);
        statistics5.setCount5(bjdjfCount);
        statistics5.setMoney5(bjdjfMoney);
        statistics5.setMoney6(bjdyhxjfMoney);
        statistics5.setCount7(bnjfCount);
        statistics5.setMoney7(bnjfMoney);
        statistics5.setMoney8(bnyhxjfMoney);*/

        statistics12.setCount1(new BigDecimal(bzjfCount));
        statistics12.setMoney1(bzjfMoney);
        statistics12.setMoney2(bzwtjjfMoney);
        statistics12.setMoney3(bzyhxjfMoney);
        statistics12.setMoney4(bzwhxjfMoney);
        statisticsService.insertNoScope(statistics12);

        statistics13.setCount1(new BigDecimal(byjfCount));
        statistics13.setMoney1(byjfMoney);
        statistics13.setMoney2(bywtjjfMoney);
        statistics13.setMoney3(byyhxjfMoney);
        statistics13.setMoney4(bywhxjfMoney);
        statisticsService.insertNoScope(statistics13);

        statistics14.setCount1(new BigDecimal(bjdjfCount));
        statistics14.setMoney1(bjdjfMoney);
        statistics14.setMoney2(bjdwtjjfMoney);
        statistics14.setMoney3(bjdyhxjfMoney);
        statistics14.setMoney4(bjdwhxjfMoney);
        statisticsService.insertNoScope(statistics14);

        statistics15.setCount1(new BigDecimal(bnjfCount));
        statistics15.setMoney1(bnjfMoney);
        statistics15.setMoney2(bnwtjjfMoney);
        statistics15.setMoney3(bnyhxjfMoney);
        statistics15.setMoney4(bnwhxjfMoney);
        statisticsService.insertNoScope(statistics15);

    }

    private void goodsSaleTable(Date insertTime, SysDept dept, GoodsStatistics statistics) {
        //销售统计
        GoodsStatistics statistics3 = new GoodsStatistics();
        //零散销售利润统计
//        GoodsStatistics statistics4 = new GoodsStatistics();
        //销售应收数据统计
        GoodsStatistics statistics9 = new GoodsStatistics();
        GoodsStatistics statistics10 = new GoodsStatistics();
        GoodsStatistics statistics11 = new GoodsStatistics();
        GoodsSale saleParam = new GoodsSale();
        Map<String, Object> saleMap = new HashMap<>();
        saleMap.put("year", DateUtils.formatDate(insertTime, "yyyy"));
        saleMap.put("statisticsDeptId", dept.getDeptId());
        saleParam.setParams(saleMap);
        List<GoodsSale> sales = saleService.selectList(saleParam);
        //销售统计     //昨日出库       //当日出库          //本周出库            //本月出库            //本季度出库            //本年出库
        BeanUtils.copyProperties(statistics, statistics3);
        statistics3.setCategory("xstj");
        //昨日出库数量,金额
        BigDecimal zrckCount = BigDecimal.ZERO;
        BigDecimal zrckMoney = BigDecimal.ZERO;
        //当日出库数量,金额
        BigDecimal drckCount = BigDecimal.ZERO;
        BigDecimal drckMoney = BigDecimal.ZERO;
        //本周出库数量,金额
        BigDecimal bzckCount = BigDecimal.ZERO;
        BigDecimal bzckMoney = BigDecimal.ZERO;
        //本月出库数量,金额
        BigDecimal byckCount = BigDecimal.ZERO;
        BigDecimal byckMoney = BigDecimal.ZERO;
        //本季度出库数量,金额
        BigDecimal bjdckCount = BigDecimal.ZERO;
        BigDecimal bjdckMoney = BigDecimal.ZERO;
        //本年出库数量,金额
        int bnckCount =0;
        BigDecimal bnckMoney = BigDecimal.ZERO;
        //出库条目数
        int ckSum  =0;

        //零散销售利润统计  //本月利润        //本季度利润        //本年利润
        /*BeanUtils.copyProperties(statistics, statistics4);
        statistics4.setCategory("xslrtj");
        //本月零散销售利润数量, 金额
        int byXslrCount = 0;
        BigDecimal byXslrMoney = BigDecimal.ZERO;
        //本季度零散销售利润数量, 金额
        int bjdXslrCount = 0;
        BigDecimal bjdXslrMoney = BigDecimal.ZERO;
        //本年零散销售利润数量, 金额
        int bnXslrCount = 0;
        BigDecimal bnXslrMoney = BigDecimal.ZERO;
        //利润条目数
        int xslrCount = 0;*/

        //销售应收统计       采购成本   销售金额       已开票      未开票     已回款     部分回款     未回款     应收        //销售利润
        BeanUtils.copyProperties(statistics, statistics9);
        BeanUtils.copyProperties(statistics, statistics10);
        BeanUtils.copyProperties(statistics, statistics11);
        statistics9.setCategory("xsys");
        statistics10.setCategory("xsys");
        statistics11.setCategory("xsys");
        statistics9.setKind("month");
        statistics10.setKind("season");
        statistics11.setKind("year");

        int byxsCount = 0;
        BigDecimal byxscbMoney = BigDecimal.ZERO;
        BigDecimal byxsjeMoney = BigDecimal.ZERO;
        BigDecimal byxskpMoney = BigDecimal.ZERO;
        BigDecimal byxswkpMoney = BigDecimal.ZERO;
        BigDecimal byxshkMoney = BigDecimal.ZERO;
        BigDecimal byxsbfhkMoney = BigDecimal.ZERO;
        BigDecimal byxswhkMoney = BigDecimal.ZERO;
        BigDecimal byxsysMoney = BigDecimal.ZERO;
        BigDecimal byxslrMoney = BigDecimal.ZERO;

        int bjdxsCount = 0;
        BigDecimal bjdxscbMoney = BigDecimal.ZERO;
        BigDecimal bjdxsjeMoney = BigDecimal.ZERO;
        BigDecimal bjdxskpMoney = BigDecimal.ZERO;
        BigDecimal bjdxswkpMoney = BigDecimal.ZERO;
        BigDecimal bjdxshkMoney = BigDecimal.ZERO;
        BigDecimal bjdxsbfhkMoney = BigDecimal.ZERO;
        BigDecimal bjdxswhkMoney = BigDecimal.ZERO;
        BigDecimal bjdxsysMoney = BigDecimal.ZERO;
        BigDecimal bjdxslrMoney = BigDecimal.ZERO;

        BigDecimal bnxscbMoney = BigDecimal.ZERO;
        BigDecimal bnxsjeMoney = BigDecimal.ZERO;
        BigDecimal bnxskpMoney = BigDecimal.ZERO;
        BigDecimal bnxswkpMoney = BigDecimal.ZERO;
        BigDecimal bnxshkMoney = BigDecimal.ZERO;
        BigDecimal bnxsbfhkMoney = BigDecimal.ZERO;
        BigDecimal bnxswhkMoney = BigDecimal.ZERO;
        BigDecimal bnxsysMoney = BigDecimal.ZERO;
        BigDecimal bnxslrMoney = BigDecimal.ZERO;

        for (GoodsSale sale : sales) {
            if ("1".equals(sale.getType())) {//只统计零散销售
                if (DateUtils.isWithinCurrentRange(sale.getSaleDate(), "yestoday")) {
                    zrckCount = zrckCount.add(sale.getGoodsCount());
                    zrckMoney = zrckMoney.add(sale.getGoodsTotalPrice());
                }
                if (DateUtils.isWithinCurrentRange(sale.getSaleDate(), "today")) {
                    drckCount = drckCount.add(sale.getGoodsCount());
                    drckMoney = drckMoney.add(sale.getGoodsTotalPrice());
                }
                if (DateUtils.isWithinCurrentRange(sale.getSaleDate(), "week")) {
                    bzckCount = bzckCount.add(sale.getGoodsCount());
                    bzckMoney = bzckMoney.add(sale.getGoodsTotalPrice());
                }
                if (DateUtils.isWithinCurrentRange(sale.getSaleDate(), "month")) {
                    byckCount = byckCount.add(sale.getGoodsCount());
                    byckMoney = byckMoney.add(sale.getGoodsTotalPrice());
                    /*byXslrCount = byXslrCount + sale.getGoodsCount();
                    byXslrMoney = byXslrMoney.add(sale.getGoodsProfit());*/
                    byxscbMoney = byxscbMoney.add(sale.getGoodsBuyTotal());
                    byxsjeMoney = byxsjeMoney.add(sale.getGoodsTotalPrice());
                    if("1".equals(sale.getInvoice())){
                        byxskpMoney = byxskpMoney.add(sale.getGoodsTotalPrice());
                    }else{
                        byxswkpMoney = byxswkpMoney.add(sale.getGoodsTotalPrice());
                    }
                    if("1".equals(sale.getFundCallback())){//全部回款
                        byxshkMoney = byxshkMoney.add(sale.getGoodsTotalPrice());
                    }else if("2".equals(sale.getFundCallback())){//部分回款
                        byxsbfhkMoney = byxsbfhkMoney.add(sale.getGoodsTotalPrice());
                    }else{//未回款
                        byxswhkMoney = byxswhkMoney.add(sale.getGoodsTotalPrice());
                    }
                    byxslrMoney = byxslrMoney.add(sale.getGoodsProfit());
                }
                if (DateUtils.isWithinCurrentRange(sale.getSaleDate(), "season")) {
                    bjdckCount = bjdckCount.add(sale.getGoodsCount());
                    bjdckMoney = bjdckMoney.add(sale.getGoodsTotalPrice());
                    /*bjdXslrCount = bjdXslrCount + sale.getGoodsCount();
                    bjdXslrMoney = bjdXslrMoney.add(sale.getGoodsProfit());*/
                    bjdxscbMoney = bjdxscbMoney.add(sale.getGoodsBuyTotal());
                    bjdxsjeMoney = bjdxsjeMoney.add(sale.getGoodsTotalPrice());
                    if("1".equals(sale.getInvoice())){
                        bjdxskpMoney = bjdxskpMoney.add(sale.getGoodsTotalPrice());
                    }else{
                        bjdxswkpMoney = bjdxswkpMoney.add(sale.getGoodsTotalPrice());
                    }
                    if("1".equals(sale.getFundCallback())){//全部回款
                        bjdxshkMoney = bjdxshkMoney.add(sale.getGoodsTotalPrice());
                    }else if("2".equals(sale.getFundCallback())){//部分回款
                        bjdxsbfhkMoney = bjdxsbfhkMoney.add(sale.getGoodsTotalPrice());
                    }else{//未回款
                        bjdxswhkMoney = bjdxswhkMoney.add(sale.getGoodsTotalPrice());
                    }
                    bjdxslrMoney = bjdxslrMoney.add(sale.getGoodsProfit());
                }
                bnckCount += sale.getGoodsCount().intValue();
                bnckMoney = bnckMoney.add(sale.getGoodsTotalPrice());
                /*bnXslrCount += sale.getGoodsCount();
                bnXslrMoney = bnXslrMoney.add(sale.getGoodsProfit());*/
                ckSum++;
                /*xslrCount++;*/
                bnxscbMoney = bnxscbMoney.add(sale.getGoodsBuyTotal());
                bnxsjeMoney = bnxsjeMoney.add(sale.getGoodsTotalPrice());
                if("1".equals(sale.getInvoice())){
                    bnxskpMoney = bnxskpMoney.add(sale.getGoodsTotalPrice());
                }else{
                    bnxswkpMoney = bnxswkpMoney.add(sale.getGoodsTotalPrice());
                }
                if("1".equals(sale.getFundCallback())){//全部回款
                    bnxshkMoney = bnxshkMoney.add(sale.getGoodsTotalPrice());
                }else if("2".equals(sale.getFundCallback())){//部分回款
                    bnxsbfhkMoney = bnxsbfhkMoney.add(sale.getGoodsTotalPrice());
                }else{//未回款
                    bnxswhkMoney = bnxswhkMoney.add(sale.getGoodsTotalPrice());
                }
                bnxslrMoney = bnxslrMoney.add(sale.getGoodsProfit());


            }
        }
        statistics3.setCount1(zrckCount);
        statistics3.setMoney1(zrckMoney);
        statistics3.setCount2(drckCount);
        statistics3.setMoney2(drckMoney);
        statistics3.setCount3(bzckCount);
        statistics3.setMoney3(bzckMoney);
        statistics3.setCount4(byckCount);
        statistics3.setMoney4(byckMoney);
        statistics3.setCount5(bjdckCount);
        statistics3.setMoney5(bjdckMoney);
        statistics3.setCount6(new BigDecimal(bnckCount));
        statistics3.setMoney6(bnckMoney);
        statistics3.setCount7(new BigDecimal(ckSum));
        statisticsService.insertNoScope(statistics3);


        statistics9.setCount(byxsCount);
        statistics9.setCount1(byckCount);
        statistics9.setMoney1(byxscbMoney);
        statistics9.setMoney2(byxsjeMoney);
        statistics9.setMoney3(byxskpMoney);
        statistics9.setMoney4(byxswkpMoney);
        statistics9.setMoney5(byxshkMoney);
        statistics9.setMoney6(byxsbfhkMoney);
        statistics9.setMoney7(byxswhkMoney);
        byxsysMoney = byxsjeMoney.subtract(byxshkMoney);
        statistics9.setMoney8(byxsysMoney);
        statistics9.setMoney9(byxslrMoney);
        statisticsService.insertNoScope(statistics9);

        statistics10.setCount(bjdxsCount);
        statistics10.setCount1(bjdckCount);
        statistics10.setMoney1(bjdxscbMoney);
        statistics10.setMoney2(bjdxsjeMoney);
        statistics10.setMoney3(bjdxskpMoney);
        statistics10.setMoney4(bjdxswkpMoney);
        statistics10.setMoney5(bjdxshkMoney);
        statistics10.setMoney6(bjdxsbfhkMoney);
        statistics10.setMoney7(bjdxswhkMoney);
        bjdxsysMoney = bjdxsjeMoney.subtract(bjdxshkMoney);
        statistics10.setMoney8(bjdxsysMoney);
        statistics10.setMoney9(bjdxslrMoney);
        statisticsService.insertNoScope(statistics10);

        statistics11.setCount(ckSum);
        statistics11.setCount1(new BigDecimal(bnckCount));
        statistics11.setMoney1(bnxscbMoney);
        statistics11.setMoney2(bnxsjeMoney);
        statistics11.setMoney3(bnxskpMoney);
        statistics11.setMoney4(bnxswkpMoney);
        statistics11.setMoney5(bnxshkMoney);
        statistics11.setMoney6(bnxsbfhkMoney);
        statistics11.setMoney7(bnxswhkMoney);
        bnxsysMoney = bnxsjeMoney.subtract(bnxshkMoney);
        statistics11.setMoney8(bnxsysMoney);
        statistics11.setMoney9(bnxslrMoney);
        statisticsService.insertNoScope(statistics11);

        /*statistics4.setCount1(byXslrCount);
        statistics4.setMoney1(byXslrMoney);
        statistics4.setCount2(bjdXslrCount);
        statistics4.setMoney2(bjdXslrMoney);
        statistics4.setCount3(bnXslrCount);
        statistics4.setMoney3(bnXslrMoney);
        statistics4.setCount4(xslrCount);
        statisticsService.insertNoScope(statistics4);*/

    }

    private void goodsOrderInTable(Date insertTime, SysDept dept, GoodsStatistics statistics) {
        //入库统计
        GoodsStatistics statistics1 = new GoodsStatistics();
        //库存统计
        GoodsStatistics statistics2 = new GoodsStatistics();
        GoodsOrderIn orderInParam = new GoodsOrderIn();
        Map<String, Object> orderInMap = new HashMap<>();
        orderInMap.put("year", DateUtils.formatDate(insertTime, "yyyy"));
        orderInMap.put("statisticsDeptId", dept.getDeptId());
        orderInParam.setParams(orderInMap);
        List<GoodsOrderIn> orderIns = orderInService.selectList(orderInParam);
        //入库统计 :     //昨日入库     //当日入库            //本周入库            //本月入库            //本季度入库            //本年入库
        BeanUtils.copyProperties(statistics, statistics1);
        statistics1.setCategory("rktj");
        //昨日入库数量,金额
        BigDecimal zrrkCount = BigDecimal.ZERO;
        BigDecimal zrrkMoney = BigDecimal.ZERO;
        //当日入库数量,金额
        BigDecimal drrkCount = BigDecimal.ZERO;
        BigDecimal drrkMoney = BigDecimal.ZERO;
        //本周入库数量,金额
        BigDecimal bzrkCount = BigDecimal.ZERO;
        BigDecimal bzrkMoney = BigDecimal.ZERO;
        //本月入库数量,金额
        BigDecimal byrkCount = BigDecimal.ZERO;
        BigDecimal byrkMoney = BigDecimal.ZERO;
        //本季度入库数量,金额
        BigDecimal bjdrkCount = BigDecimal.ZERO;
        BigDecimal bjdrkMoney = BigDecimal.ZERO;
        //本年入库数量,金额
        int bnrkCount = 0;
        BigDecimal bnrkMoney = BigDecimal.ZERO;
        //入库条目数
        int rkSum = 0;

        //库存统计 10天内库存                //20天内库存                //30天内库存                //30天以上
        BeanUtils.copyProperties(statistics, statistics2);
        statistics2.setCategory("kctj");
        //10天内库存
        BigDecimal kcCount0 = BigDecimal.ZERO;
        BigDecimal kcMoney0 = BigDecimal.ZERO;
        //10天-20天库存
        BigDecimal kcCount10 = BigDecimal.ZERO;
        BigDecimal kcMoney10 = BigDecimal.ZERO;
        //20天-30天内库存
        BigDecimal kcCount20 = BigDecimal.ZERO;
        BigDecimal kcMoney20 = BigDecimal.ZERO;
        //30天以上库存
        BigDecimal kcCount30 = BigDecimal.ZERO;
        BigDecimal kcMoney30 = BigDecimal.ZERO;
        //库存条目数
        BigDecimal kcCount = BigDecimal.ZERO;
        BigDecimal kcMoney = BigDecimal.ZERO;
        //库存条目数
        int kcSum = 0;

        for (GoodsOrderIn orderIn : orderIns) {
            if (DateUtils.isWithinCurrentRange(orderIn.getBuyDate(), "yestoday")) {
                zrrkCount = zrrkCount.add(orderIn.getCount());
                zrrkMoney = zrrkMoney.add(orderIn.getCost());
            }
            if (DateUtils.isWithinCurrentRange(orderIn.getBuyDate(), "today")) {
                drrkCount = drrkCount.add(orderIn.getCount());
                drrkMoney = drrkMoney.add(orderIn.getCost());
            }
            if (DateUtils.isWithinCurrentRange(orderIn.getBuyDate(), "week")) {
                bzrkCount = bzrkCount.add(orderIn.getCount());
                bzrkMoney = bzrkMoney.add(orderIn.getCost());
            }
            if (DateUtils.isWithinCurrentRange(orderIn.getBuyDate(), "month")) {
                byrkCount = byrkCount.add(orderIn.getCount());
                byrkMoney = byrkMoney.add(orderIn.getCost());
            }
            if (DateUtils.isWithinCurrentRange(orderIn.getBuyDate(), "season")) {
                bjdrkCount = bjdrkCount.add(orderIn.getCount());
                bjdrkMoney = bjdrkMoney.add(orderIn.getCost());
            }
            bnrkCount += orderIn.getCount().intValue();
            bnrkMoney = bnrkMoney.add(orderIn.getCost());
            rkSum++;
            if (orderIn.getRemainderCount().compareTo(BigDecimal.ZERO)>0) {
                if (DateUtils.isWithinDayRange(orderIn.getBuyDate(), 0, 10)) {
                    kcCount0 = kcCount0.add(orderIn.getCount());
                    kcMoney0 = kcMoney0.add(orderIn.getCost());
                } else if (DateUtils.isWithinDayRange(orderIn.getBuyDate(), 10, 20)) {
                    kcCount10 = kcCount10.add(orderIn.getCount());
                    kcMoney10 = kcMoney10.add(orderIn.getCost());
                } else if (DateUtils.isWithinDayRange(orderIn.getBuyDate(), 20, 30)) {
                    kcCount20 = kcCount20.add(orderIn.getCount());
                    kcMoney20 = kcMoney20.add(orderIn.getCost());
                } else if (DateUtils.isWithinDayRange(orderIn.getBuyDate(), 30, 100000)) {
                    kcCount30 = kcCount30.add(orderIn.getCount());
                    kcMoney30 = kcMoney30.add(orderIn.getCost());
                }
                kcCount = kcCount.add(orderIn.getCount());
                kcMoney = kcMoney.add(orderIn.getCost());
                kcSum++;
            }
        }
        statistics1.setCount1(zrrkCount);
        statistics1.setMoney1(zrrkMoney);
        statistics1.setCount2(drrkCount);
        statistics1.setMoney2(drrkMoney);
        statistics1.setCount3(bzrkCount);
        statistics1.setMoney3(bzrkMoney);
        statistics1.setCount4(byrkCount);
        statistics1.setMoney4(byrkMoney);
        statistics1.setCount5(bjdrkCount);
        statistics1.setMoney5(bjdrkMoney);
        statistics1.setCount6(new BigDecimal(bnrkCount));
        statistics1.setMoney6(bnrkMoney);
        statistics1.setCount7(new BigDecimal(rkSum));
        statisticsService.insertNoScope(statistics1);

        statistics2.setCount1(kcCount0);
        statistics2.setMoney1(kcMoney0);
        statistics2.setCount2(kcCount10);
        statistics2.setMoney2(kcMoney10);
        statistics2.setCount3(kcCount20);
        statistics2.setMoney3(kcMoney20);
        statistics2.setCount4(kcCount30);
        statistics2.setMoney4(kcMoney30);
        statistics2.setCount5(kcCount);
        statistics2.setMoney5(kcMoney);
        statistics2.setCount6(kcCount);
        statisticsService.insertNoScope(statistics2);
    }

}
